package xq.gwt.ui.widgets.command;

import com.smartgwt.client.widgets.toolbar.ToolStrip;

import xq.gwt.mvc.model.CommandModel;

import com.smartgwt.client.widgets.Canvas;

public class ToolStripCommandListPresenter implements CommandListPresenter {
	protected CommandModel[] commands;
	protected ToolStrip toolstrip;
	
	
	public ToolStripCommandListPresenter(){
		toolstrip = new ToolStrip();
		init();
	}
	
	public ToolStripCommandListPresenter(ToolStrip toolstrip){
		this.toolstrip = toolstrip;
		init();
	}
	
	private void init(){
		toolstrip.setWidth100();
	}

	@Override
	public void setCommands(CommandModel[] commands){
		toolstrip.clear();
		if (commands == null){
			return;
		}
		for (int i = 0; i < commands.length; i++) {
			ToolStripButtonCommandPresenter commandPresenter = new ToolStripButtonCommandPresenter();
			commandPresenter.setModel(commands[i]);
			toolstrip.addButton(commandPresenter.getButton());
			if (i != commands.length -1){
				toolstrip.addSeparator();
			}
		}		
	}
	
	@Override
	public Canvas getCanvas(){
		return toolstrip;
	}
}
